layui.use(['jquery','layer'],function () {
    var $ = layui.$,
        layer = layui.layer;

    var msgId = getUrlParms("msgId");
    var managerId = getCookie("managerId");
    $.ajax({
        url : "/CivilAffairs/msg/getOneMsgInfo",
        type : "post",
        data : {"msgId":msgId,"managerId":managerId},
        async : false,
        dataType : "json",
        success : function(result) {
            if(checkResult(result)){
                var msg = result.data;
                $("#reportContent").html(msg.MSG_CONTENT);
                $("#msgType").val(msg.MSG_TYPE);
                $("#name").val(msg.REAL_NAME);
                if(!isNull(msg.TELEPHONE)){
                    $("#telephone").val(msg.TELEPHONE);
                }
                if(!isNull(msg.ADDRESS)){
                    $("#address").val(msg.ADDRESS);
                }
                $("#readMsg").attr("itemtype",msg.READ_TAG);
                $("#readMsg").attr("itemid",msg.MSG_ID);
            }
        },
        error:function(result){
            reqError(result,"删除信息异常");
        }
    });

    //点击关闭页面
    $("body").on("click","#readMsg",function () {
        var readTag = $(this).attr("itemtype");
        //如果是已读消息,不再做阅读操作
        if("0"==readTag){
            var readMsgId = $(this).attr("itemid");
            $.ajax({
                url : "/CivilAffairs/msg/readMsg",
                type : "post",
                data : {"msgId":readMsgId,"managerId":managerId},
                async : false,
                dataType : "json",
                success : function(result) {
                    if("0000"==result.status){
                        var msgNum = top.document.getElementById("msgNum");
                        //获取消息数目
                        $.ajax({
                            url : "/CivilAffairs/msg/getMsgNum",
                            type : "post",
                            async : false,
                            data: {"managerId":managerId},
                            dataType : "json",
                            success : function(result) {
                                if("9999"==result.status){
                                    console.log("获取消息总数异常:managerId:"+managerId+","+result.status+","+result.statusMessage);
                                }else{
                                    $(msgNum).text(result.data);
                                }
                            },
                            error : function(result) {
                                reqError(result,"获取未读消息异常");
                            }
                        });
                    }
                },
                error:function(result){
                    console.log("阅读消息异常:msgId:"+readMsgId+","+result.status+","+result.statusMessage);
                }
            });
        }
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        //刷新父页面
        parent.location.reload();
    });
});